// cheng/pages/money/money.js
var app = getApp(), md5 = require('../../../utils/md5.js'), helper = require('../../../utils/helper.js');
Page({
  data: {
    appUserInfo:{},
    money:0,
    push_type:0,
    qrcode_img:'',
    msg:'',
    result:99,
    hosId:app.args.api.siteinfo.hosId2,
  },
  onLoad: function (o) {
    //console.log('HB_money')
    //console.log(o)
    var appUserInfo=wx.getStorageSync('appUserInfo');
    //console.log(appUserInfo)
    if(appUserInfo){
      this.setData({appUserInfo, parmas:o, _api_live: app.args.api.siteinfo.sitelive})
      this.getRed(o,appUserInfo)
    }
  },
  getRed(o,info){
    var t = this,s = "d="+helper.formatData()+"&h="+app.args.api.siteinfo.acid+"&l="+o.liveId+"&o="+wx.getStorageSync('ACCESS_TOKEN');
    wx.showLoading()
    wx.request({
      url: t.data._api_live + "hbActionGZH/getHB",
      data:{
        storeId:app.args.api.siteinfo.acid,
        access_token:wx.getStorageSync('ACCESS_TOKEN'),
        liveId:o.liveId,
        mobile:info.phone,
        hbcount:o.count,
        hb_batch_id:o.id,
        pstr:md5.hex_md5(s)
      },
      success(e){
        /* console.log("加密前",s)
        console.log("加密后",md5.hex_md5(s))
        console.log(e) */
        e = e.data;
        //console.log('getRed:',e)
        wx.hideLoading()
        if(e.code == 0 && e.result == 0){
          t.setData({
            money:e.money,
            result:e.result,
            push_type:e.push_type,
            qrcode_img:e.qrcode_img,
            msg:e.msg
          })
          if(e.msg){
            wx.showToast({icon:'none',title:e.msg})
          }
        }else{
          t.setData({
            result:-1
          })
        }
      },
      fail() {
        t.setData({
          result:-1
        })
      }
    })
  },
  go(){
    wx.navigateBack({delta: 1})
  }
})